<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box1 {
            width: 400px;
            margin: 200px auto;
        }

        .box1 img {
            float: left;
            display: block;
            width: 100px;
            height: 60px;
        }
    </style>
</head>

<body>
    <div class="box1">
        <img src="images/鬼刀冰公主5.jpg" alt="">
        <img src="images/鬼刀冰公主6.jpg" alt="">
        <img src="images/鬼刀冰公主7.jpg" alt="">
        <img src="images/鬼刀冰公主8.jpg" alt="">
    </div>
    <script>
        // var imgs = document.querySelectorAll('img');
        // var body = document.body;
        // for (let i = 0; i < imgs.length; i++) {
        //     imgs[i].onclick = function () {
        //         body.style.backgroundImage = 'url(images/鬼刀冰公主' + (i+5) + '.jpg)';
        //     }
        // }
        var imgs = document.querySelectorAll('img');
        for (let i = 0; i < imgs.length; i++) {
            imgs[i].onclick = function () {
                document.body.style.backgroundImage = 'url('+this.src+')';
            }
        }
    </script>
</body>

</html>